package com.zhouz.admin.app.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhouz.admin.app.annotation.RequiresPermissionsDesc;
import com.zhouz.admin.app.aop.LogAnno;
import com.zhouz.admin.app.db.domain.SysDic;
import com.zhouz.admin.app.db.service.SysDicService;
import com.zhouz.admin.app.db.vo.Result;
import com.zhouz.admin.app.vo.SysDicReqVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;


/**
 *
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2019-07-03 01:25:49
 */
@RestController
@RequestMapping("/admin/sysdic")
public class AdminSysDicController {
    @Autowired
    private SysDicService sysDicService;
    @RequiresPermissions("admin:sysdic:list")
    @RequiresPermissionsDesc(menu = {"系统管理","数据字典"}, button = "列表")
    @GetMapping("/list")
    public Result list(SysDicReqVo req) {
        QueryWrapper<SysDic> wrapper = req.getSelectQuery();
        wrapper.orderByDesc(SysDic.Column.createTime.getValue());
        return Result.success(sysDicService.page(req.getSelectPage(), wrapper));

    }

    /**
     * 信息
     */
    @GetMapping("/info")
    @RequiresPermissionsDesc(menu = {"系统管理","数据字典"}, button = "信息")
    @RequiresPermissions("admin:sysdic:info")
    public Result<SysDic> info(@RequestParam Integer id){
        SysDic sysDic = sysDicService.getById(id);
        return Result.success(sysDic);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @RequiresPermissionsDesc(menu = {"系统管理","数据字典"}, button = "保存")
    @RequiresPermissions("admin:sysdic:save")
    @LogAnno(urlDesc = "数据字典-保存")
    public Result save(@RequestBody SysDic sysDic){
		sysDicService.saveOrUpdate(sysDic);
        return Result.success();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    @RequiresPermissions("admin:sysdic:delete")
    @RequiresPermissionsDesc(menu = {"系统管理","数据字典"}, button = "删除")
    @LogAnno(urlDesc = "数据字典-删除")
    public Result delete(@RequestBody Integer[] ids){
		sysDicService.removeByIds(Arrays.asList(ids));
        return Result.success();
    }

}
